package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Tag(name="分类管理接口", description = "分类管理")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    @GetMapping("/page")
    @Operation(summary = "分类管理分页查询", description = "分类管理分页查询")
    public Result<PageResult> pageList (CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("用户分页查询参数: {}", categoryPageQueryDTO);
        PageResult result = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(result);
    }

    @PutMapping
    @Operation(summary = "修改分类", description = "修改分类")
    public Result<String> update (@RequestBody CategoryDTO categoryDTO) {
        log.info("用户修改分类参数: {}", categoryDTO);
        categoryService.updateCate(categoryDTO);
        return Result.success("");
    }

    @PostMapping("/status/{status}")
    @Operation(summary = "修改分类启用禁用状态", description = "修改分类启用禁用状态")
    public Result<String> updateStatus (@PathVariable Integer status, Long id) {
        log.info("修改分类启用禁用状态: 状态值 {}, id: {}", status, id);
        categoryService.updateStatus(status, id);
        return Result.success("");
    }

    @PostMapping
    @Operation(summary="新增套餐分类",description = "新增套餐分类")
    public Result<String> add (@RequestBody CategoryDTO categoryDTO) {
        log.info("新增套餐分类: CategoryDTO {}",categoryDTO);
        categoryService.updateCate(categoryDTO);
        return Result.success("");
    }

    @DeleteMapping
    @Operation(summary = "删除套餐分类", description = "删除套餐分类")
    public Result<String> delCate (Long id) {
        log.info("套餐ID {}：",id);
        categoryService.delCate(id);
        return Result.success("");
    }

    @GetMapping("/list")
    @Operation(summary = "根据类型查询分类", description = "根据类型查询分类")
    public Result<ArrayList<CategoryDTO>> list (Integer type) {
        log.info("用户根据类型查询参数: {}", type);
        ArrayList<CategoryDTO> result = categoryService.list(type);
        return Result.success(result);
    }
}
